package cn.com.chengmandian.bike.service.impl;

import cn.com.chengmandian.bike.mapper.EbMessageChannelMapper;
import cn.com.chengmandian.bike.model.EbMessageChannel;
import cn.com.chengmandian.bike.model.vo.MessageChannelVo;
import cn.com.chengmandian.bike.service.IEbMessageChannelService;
import cn.com.chengmandian.core.common.constants.CommonConstant;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 电单车运营-系统消息频道 服务实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2021-12-30
 */
@Service
public class EbMessageChannelServiceImpl extends ServiceImpl<EbMessageChannelMapper, EbMessageChannel> implements IEbMessageChannelService {

    @Resource
    private EbMessageChannelMapper messageChannelMapper;

    @Override
    public List<MessageChannelVo> selectMessageChannelList(Integer id) {
        return messageChannelMapper.selectMessageChannelList(id);
    }

    @Override
    public EbMessageChannel getSysByName(String channelName) {
        EbMessageChannel messageChannel = this.getOne(new LambdaQueryWrapper<EbMessageChannel>().eq(EbMessageChannel::getName, channelName.trim()));
        if (messageChannel == null) {
            messageChannel = new EbMessageChannel();
            messageChannel.setName(channelName);
            messageChannel.setType(CommonConstant.ONE);
            this.save(messageChannel);
        }
        return messageChannel;
    }


}
